package com.example.myapplication.douyinminiappscrolldemo

import android.os.Bundle
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

    private lateinit var webView: WebView
    private lateinit var overlayLinearLayout: LinearLayout

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        webView = findViewById(R.id.webView)
        overlayLinearLayout = findViewById(R.id.overlayLinearLayout)

        // 配置 WebView
        webView.settings.javaScriptEnabled = true
        webView.webViewClient = WebViewClient()
//        webView.loadUrl("https://www.weibo.com") // 替换为实际的 URL
        webView.loadUrl("file:///android_asset/local.html")

        // 监听 WebView 滚动事件
        webView.setOnScrollChangeListener { _, _, scrollY, _, _ ->
            // 同步覆盖组件的位置
            overlayLinearLayout.translationY = 500f - scrollY.toFloat()
        }
    }
}